package com.czm.art_light.patterns.chainOfResponsibility.impl;


import com.czm.art_light.constant.CommonConsts;
import com.czm.art_light.context.UserActionStrategyContext;
import com.czm.art_light.entity.ArtUserActions;
import com.czm.art_light.param.request.UserActionReqDto;
import com.czm.art_light.patterns.chainOfResponsibility.UserActionHandler;
import com.czm.art_light.service.ArtUserActionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 记录行为处理器
 */
@Component
public class LogActionHandler implements UserActionHandler {
    @Autowired
    private UserActionStrategyContext userActionStrategyContext;

    @Autowired
    private ArtUserActionsService artUserActionsService;

    @Override
    public void handle(UserActionReqDto userActionReqDto) {
        // 将用户行为记录到数据库
//        userActionStrategyContext.getSaveOrderStrategy(userActionReqDto.getActionType().getValue()).recordUserActions(userActionReqDto);
        artUserActionsService.recordUserActions(ArtUserActions.builder()
                //用户id
                .userId(userActionReqDto.getUserId())
                //作品id
                .workId(userActionReqDto.getWorkId())
                //操作类型：点击
                .actionType(userActionReqDto.getActionType().getValue())
                //操作时间(当前时间)
                .actionTime(LocalDateTime.now())
                .build());
    }

    @Override
    public Integer sort() {
        return CommonConsts.ChainSortEnum.SORT_1.getSort();
    }
}